﻿using System;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NPMonitor.DataModel;
using NPMonitor.DataModel.Internal;
using NPMonitor.Implementation;
using NPMonitor.Implementation.Internal;
using NPMonitor.Interfaces;
using NPMonitor.Interfaces.Internal;
using NPMonitor.Helpers;

namespace NPMonitor.Launcher.Tests.Service
{
    [TestClass]
    public class JobFileLoaderTest
    {
        [TestMethod]
        public void NewInstanceTest()
        {
            AppDomainSetup domainInfo = new AppDomainSetup
            {
                ApplicationBase = AppDomain.CurrentDomain.BaseDirectory,
                PrivateBinPath = "bin"
            };

            AppDomain appDomain = AppDomain.CreateDomain("JobFileDomain", null, domainInfo);
            JobFileLoader jobFileLoader = JobFileLoader.NewLoaderInstance(appDomain);

            JobFileInfo jobFileInfo = jobFileLoader.RetrieveJobFileInfo(@"D:\git\DSM\NPMonitor\Buy360Test\bin\Debug\Buy360Test.exe");

            Assert.IsNotNull(jobFileLoader);
        }

        [TestMethod]
        public void JobFileDownloadTest()
        {
            JobData jobData = StoreManager.Current.JobStore.GetScheduleReadyJobs("Test-001", Helpers.Utils.CurrentServerUtcTime).FirstOrDefault();

            if (jobData != null)
            {
                JobDefinition jobDefinition = StoreManager.Current.JobDefinitionStore.GetJobDefinitionById(jobData.TaskId.Value);

                FileManager.Download(jobDefinition);

                string filePath = FileManager.GetUploadedFilePath(jobDefinition.FileName);

                Assert.IsTrue(System.IO.File.Exists(filePath));
            }
        }
    }
}
